package T01_test_all.test07_Role;

import java.util.Random;

public class Role {
    private String name;
    private int blood;
    private char gender;
    private String face;

    String[] boyFaces = {"风流俊雅","器宇轩昂","相貌英俊","五官端正","相貌平平","一塌糊涂","面目狰狞"};
    String[] girlFaces = {"美奂绝伦","沉鱼落雁","亭亭玉立","身材姣好","相貌平平","相貌简陋","惨不忍睹"};

    public  Role(){
    }
    public Role(String name, int blood, char gender) {
        this.name = name;
        this.blood = blood;
        this.gender = gender;
        setFace(gender);
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public String getFace() {
        return face;
    }

    public void setFace(char gender) {
        Random r = new Random();
        if(gender == '男'){
            int index = r.nextInt(boyFaces.length);
            this.face = boyFaces[index];
        }else if(gender == '女'){
            int index = r.nextInt(boyFaces.length);
            this.face = girlFaces[index];
        }else {
            this.face = "妖怪，那里逃";
        }
        this.face = face;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

//    定义一个方法去攻击别人
    public void attack(Role role){
        //  计算造成的伤害
        Random r = new Random();
        int hurt = r.nextInt(20) + 1;

        // 剩余血量
        int remainBoold = role.getBlood() - hurt;
        // 防止血量为负数
        remainBoold = remainBoold < 0 ? 0 :remainBoold;
        //修改挨揍的人的血量
        role.setBlood(remainBoold);

        // this 表示方法的调用者
        System.out.println(this.getName() + "打了" + role.getName() + "，造成了" + hurt + "点伤害，" + role.getName() + "还剩下" + remainBoold + "点血");
    }

    public void showRoleInfo(){
        System.out.println("姓名：" + getName());
        System.out.println("性别：" + getGender());
        System.out.println("血量：" + getBlood());
        System.out.println("颜值：" + getFace());
    }

}
